﻿using Architecture.API.Application.Command.UserInfoCommand;
using Architecture.Domain;
using Architecture.Domain.Dto.UserInfoRoleDto;
using Architecture.Domain.Service.UserInfoServices;
using MediatR;

namespace Architecture.API.Application.CommandHandlers.UserInfoHandler
{
    /// <summary>
    /// 用户登录命令处理器
    /// </summary>
    public class UserInfoLoginCommandHandler : IRequestHandler<UserInfoLoginCommand, UserInfoRoleInfoDto>
    {
        /// <summary>
        /// 用户信息服务
        /// </summary>
        private readonly IUserInfoService _userInfoService;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="userInfoService">用户信息服务</param>
        public UserInfoLoginCommandHandler(IUserInfoService userInfoService)
        {
            _userInfoService = userInfoService;
        }

        /// <summary>
        /// 处理登录命令
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<UserInfoRoleInfoDto> Handle(UserInfoLoginCommand request, CancellationToken cancellationToken)
        {
            return await _userInfoService.UserInfoLogin(request.UserName,request.UserPwd);
        }
    }
}
